package com.briup.app01.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.briup.app01.bean.Customer;
import com.briup.app01.service.CustomerService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/customer")
@Api(description="客户信息的管理")
public class CustomerController {
	@Autowired
	private CustomerService custService;
	
	@GetMapping("/insert")
	//http://localhost:8002/customer/save?custId=10&custName=hello&custRegion=%E5%8D%8E%E5%8D%97
	//浏览器中传递的key值，一定要和customer中的属性保持一致
	public String save(Customer customer) {
		custService.save(customer);
		
		return "保存成功";
		
	}
	
	@GetMapping("/deleteById")
	@ApiOperation("根据ID删除客户信息")
	@ApiImplicitParam(name = "id",value="客户id")
	public String deleteById(int id) {
		custService.deleteById(id);
		return "删除成功";
	}
	
	@GetMapping("/update")
	public String update(Customer customer) {
		custService.update(customer);
		return "更新成功";
	}
	
	@GetMapping("/selectById")
	public Customer selectById(int id) {
		Customer customer = custService.selectById(id);
		return customer;
	}
	
	
	@GetMapping("/selectAll")
	public List<Customer> selectAll(){
		return custService.selectAll();
	}
	
	
	
	
}
